package sala.commonmovie.mainmenu 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import sala.events.MainMenuEvent;
	import sala.model.AlbumInfo;
	
	/**
	 * ...
	 * @author Sun
	 */
	public class MainMenuItem extends MovieClip
	{
		public var labelTf:TextField;
		
		private var albumInfo:AlbumInfo;
		private var _active: Boolean = false;
		public function MainMenuItem() 
		{
			this.buttonMode = true;
			this.mouseChildren = false;
			this.addEventListener(MouseEvent.CLICK, mainMenuItemClickedHdl);
			this.addEventListener(MouseEvent.ROLL_OVER, maniMenuItemRollOverHdl); 
			this.addEventListener(MouseEvent.ROLL_OUT, maniMenuItemRollOutHdl); 
		}
		
		private function maniMenuItemRollOverHdl(e:MouseEvent):void 
		{
			this.labelTf.textColor = 0x1667B2; 
		}
		
		private function maniMenuItemRollOutHdl(e:MouseEvent):void 
		{
			if (!active) this.labelTf.textColor = 0x888888; 
		}
		
		private function mainMenuItemClickedHdl(e:MouseEvent):void 
		{
			if (!active)
			{
				var evt: MainMenuEvent = new MainMenuEvent(MainMenuEvent.MAIN_MENU_ITEM_CLICKED);
				evt.albumInfo = albumInfo;
				dispatchEvent(evt);
			}
		}
		
		public function updateMainMenuItem(aInfo:AlbumInfo): void
		{
			albumInfo = aInfo;
			labelTf.text = albumInfo.name;
		}
		
		public function get active():Boolean { return _active; }
		
		public function set active(value:Boolean):void 
		{
			_active = value;
			if (value)
			{
				this.labelTf.textColor = 0xF4781F;
				this.mouseEnabled = false; 
			}
			else
			{
				this.labelTf.textColor = 0x888888;
				this.mouseEnabled = true; 
			}
		}
	}

}